package yh.design.strategy;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
import yh.design.annotation.PayStrategy;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zyh
 * @date: 2025/5/19 11:23
 **/
@Component
public class IPayContextMap_3 {


    //支付算法策略组
    public static Map<Integer, IPayment> payStrtegyMap = new HashMap<>();


    //Spring 自动注入所有 IPayment 实现类（List<IPayment> payList）。
    public  IPayContextMap_3(List<IPayment> payList){
        payList.forEach(item ->{
            PayStrategy annotation = AnnotationUtils.findAnnotation(item.getClass(), PayStrategy.class);
            if (null != annotation){
                payStrtegyMap.put(annotation.pay().getPayWay(),item);
            }
        });
    }



}
